<?php
/**
* @software         [JiJinCMS]
* @author           [上海集锦信息科技有限公司]
* @website          [http://www.jijinweb.com]
* @email            [sunny@jijinweb.com]
**/
namespace app\admin\validate;
use think\validate;
use think\facade\Db;
use think\facade\Request;
class TableValidate extends validate{
    protected $regex = [ 'checkName' => '/^[a-z_0-9wd_]+$/'];
    public $rule = [
        'name'  => ['require', 'unique'=>"table"],
        'table_name'  => ['require','regex'=>'checkName','unique'=>'table',"checkTable"],
    ];
    protected $message = [
        'name.require'=>'请填写数据表别名',
        'name.unique'=>'数据表别名已存在',
        'table_name.require'=>'请输入表名！',
        'table_name.regex'=>'表名只支持小写英文数字和下划线',
        'table_name.unique'=>'表名已存在',
        'table_name.checkTable'=>'数据库里已有此表',
    ];
    //验证数据表是否已存在
    protected function checkTable($value, $rule){
        return !table_exists("cms_".$value);
    }
}

